// src/app/services/app.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, of } from 'rxjs';

export interface Book {
  id: number;
  title: string;
  author: string;
  category: string;
  rating: number;
  price: number;
  sales: number;
  coverUrl?: string;
}

@Injectable({
  providedIn: 'root'
})
export class HomeService {
  private _keyStrategy = new BehaviorSubject<string>('id');
  readonly keyStrategy$ = this._keyStrategy.asObservable();


  private _books = new BehaviorSubject<Book[]>([
    { id: 1, title: 'Algorithm Design', author: 'John Doe', category: 'Computer Science', rating: 4.8, price: 89.99, sales: 1200, coverUrl: 'assets/images/book1.jpg' },
    { id: 2, title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', category: 'Fiction', rating: 4.5, price: 35.50, sales: 950, coverUrl: 'assets/images/book2.jpg' },
    { id: 3, title: 'Introduction to AI', author: 'Jane Smith', category: 'Computer Science', rating: 4.9, price: 120.00, sales: 1500, coverUrl: 'assets/images/book3.jpg' },
    { id: 4, title: 'History of the World', author: 'H.G. Wells', category: 'History', rating: 4.2, price: 50.00, sales: 700, coverUrl: 'assets/images/book4.jpg' },
    { id: 5, title: 'The Art of Programming', author: 'Donald Knuth', category: 'Computer Science', rating: 5.0, price: 150.00, sales: 2000, coverUrl: 'assets/images/book5.jpg' },
    { id: 6, title: 'Quantum Physics', author: 'Richard Feynman', category: 'Science', rating: 4.7, price: 110.00, sales: 800, coverUrl: 'assets/images/book6.jpg' },
    { id: 7, title: 'Classic Cook Book', author: 'Julia Child', category: 'Cooking', rating: 4.6, price: 45.00, sales: 600, coverUrl: 'assets/images/book7.jpg' },
    { id: 8, title: 'Machine Learning Basics', author: 'Andrew Ng', category: 'Computer Science', rating: 4.9, price: 99.00, sales: 1800, coverUrl: 'assets/images/book8.jpg' },
    { id: 9, title: 'The Alchemist', author: 'Paulo Coelho', category: 'Fiction', rating: 4.4, price: 28.00, sales: 1100, coverUrl: 'assets/images/book9.jpg' },
    { id: 10, title: 'Deep Learning', author: 'Ian Goodfellow', category: 'Computer Science', rating: 4.9, price: 130.00, sales: 1700, coverUrl: 'assets/images/book10.jpg' },
  ]);
  readonly books$ = this._books.asObservable();

  constructor() { }

  updateKeyStrategy(strategy: string) {
    this._keyStrategy.next(strategy);
  }

  get keyStrategy(): string {
    return this._keyStrategy.value;
  }

  getBooks(): Observable<Book[]> {
    return this.books$;
  }
}